const fs = require('fs')
const path = require('path')

console.log(path.join(__dirname, './resources/为学.md'))
console.log(__filename)

// 读取【为学】
function readWeixue() {
    return new Promise((resolve, reject) => {
        fs.readFile(path.join(__dirname, './resources/为学.md'), (err, data) => {
            if(err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
}

// 读取【插秧诗】
function readChayangshi() {
    return new Promise((resolve, reject) => {
        fs.readFile(path.join(__dirname, './resources/插秧诗.md'), (err, data) => {
            if(err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
}

// 读取【观书有感】
function readGUanshuyougan() {
    return new Promise((resolve, reject) => {
        fs.readFile(path.join(__dirname, './resources/观书有感.md'), (err, data) => {
            if(err) {
                reject(err)
            } else {
                resolve(data)
            }
        })
    })
}

// 通过async函数，顺序打印【为学】、【插秧诗】、【观书有感】
async function readAll() {
    let weixue = await readWeixue() 
    let chayang = await readChayangshi() 
    let guanshu = await readGUanshuyougan() 
    console.log(weixue.toString('utf-8')) 
    console.log(chayang.toString()) 
    console.log(guanshu.toString()) 
}
readAll() 



